<?php

/**
 * Description of delete
 *
 * @author laimis
 */
class GalleryDelete  extends ActionBase {
    public $title = 'Gallery delete';

    public function doDelete(){
        if($this->getGalleryService() != null){
            $this->galleryService->delete($_REQUEST['request']['arg']);
        }
        if($this->getPhotoService() != null){
            $photos = $this->photoService->getByGalleryId($_REQUEST['request']['arg']);
            if($photos != null){
                foreach ($photos as $photo){
                    unlink(BASEURL.$photo->original);
                    unlink(BASEURL.$photo->mini);
                    unlink(BASEURL.$photo->midi);
                    unlink(BASEURL.$photo->maxi);
                    $this->photoService->delete($photo->id);
                }
            }
        }
    }

    public function GalleryDelete(){
        if($this->getAccount() != null){
            if($_REQUEST['request']['arg'] > 0){
                $this->doDelete();
            }
            $_REQUEST['request']['action'] = 'list';
            new GalleryWrapper();
        }
    }
}
?>
